/**
 * Created by wangguoqing on 2017/11/8.
 */
var width = $(window).width();
var height = $(window).height();

$(function(){
    initPage();
    initDbsx();
    refreshModuleCommon();
});

function openCommonMenu(menuCode){
    var params = new Object();
    params.menuCode = menuCode;
    $.ajax({
        type:"POST",
        url:path+"/system/register/queryByCode",
        data:params,
        dataType:"json",
        success:function callback(data){
            var analyMsg = data;
            if (analyMsg.code!="0000") {
                //$.messager.alert('友情提醒',analyMsg.msg,'info',function(){});
            } else {
                parent.addTab(analyMsg.returnObject['menuName'], analyMsg.returnObject['menuUrl'], "", analyMsg.returnObject['menuCode']);
            }
        },
        error : function(data,textstatus){
            $.alert("default", "error", data.responseText);
        }
    });
}

function initPage(){
    //document.getElementById("iframe_gljsc").src = path+"/税金没有";
    $("#div_gljsc").height(height-200);
    $("#div_cygn").width("94%");
    $("#div_cygn1").height(height-200);
    $("#div_cygn").height(height-213);

    $("#module_left1").height(height-160);
    $("#module_right1").height(height-160);
    hoverDhl("div_gljsc");
}

/**
 * 获取待办事项条数
 */
function initDbsx() {
    $.ajax({
        type:"POST",
        url:"/tdm-web/tdm/matterBase/getMatterCount",
        data:{},
        dataType:"json",
        success:function callback(data){
            if(data!=null){
                var total = data.total;
                $("#span_dbsx").html(total);
            }
        },
        error : function(data,textstatus){
            $.alert("default", "error", data.responseText)
        }
    });
}

function getDbsx(){
   /* if ($("#span_dbsx").html() > 0){
        openCommonMenu(4050);
    }*/
    openCommonMenu(4050);
}

function getYjts(){
    if ($("#span_yjts").html() > 0){
        layer.alert("预警提示信息", {closeBtn: 0, shift: 4 });
    } else {

    }
}

function getQtts(){
    if ($("#span_qtts").html() > 0){
        layer.alert("其他提示信息", {closeBtn: 0, shift: 4 });
    } else {

    }
}

function moreModule(){
    var menuDto = new refTree('menuDto','更多功能');
    var object = new Object();
    menuDto.url = path+'/system/syswelcome/getCurrentMenu';
    menuDto.parameters = object;
    menuDto.callBack = moduleCommon;
    menuDto.singleLoad = 0;
    menuDto.selectedMulti = 1;
    menuDto.init();
    menuDto.openRef();
}

function moduleCommon(){
    var zTree = $.fn.zTree.getZTreeObj('menuDto');
    var checkNodes = zTree.getCheckedNodes(true);
    var menuCodes="";

    for(var i=0; i<checkNodes.length; i++){
        if(menuCodes==""){
            menuCodes=checkNodes[i].code;
        }else{
            menuCodes = menuCodes+','+checkNodes[i].code;
        }
    }
    var params = new Object();
    params.menuCodes = menuCodes;
    $.ajax({
        type:"POST",
        url:path+"/system/syswelcome/saveModuleCommon",
        data:params,
        dataType:"json",
        success:function callback(data){
            var analyMsg = data;
            if (analyMsg.code!="0000") {
                $.messager.alert("操作提示", analyMsg.msg, "info", function () {
                });
            } else {
                $.messager.alert("操作提示", analyMsg.msg, "info", function () {
                    refreshModuleCommon();
                });
            }
        },
        error : function(data,textstatus){
            $.messager.alert("操作提示", data.responseText, "error", function () {
            });
        }
    });
}

function refreshModuleCommon(){

    var s_add = '<li><a href="javascript:moreModule();" class="ico-add"></a></li>';
    var s = '<ol>';

    var params = new Object();
    $.ajax({
        type:"POST",
        url:path+"/system/syswelcome/listCurrentCommonMenu",
        data:params,
        dataType:"json",
        async: false,
        success:function callback(data){
            var analyMsg = data;
            if (analyMsg.code!="0000") {
                //$.messager.alert('友情提醒',analyMsg.msg,'info',function(){});
                $.alert("default", "error", analyMsg.msg);
            } else {
                for (var i=0; i<analyMsg.returnObject.rows.length; i++) {
                    if (analyMsg.returnObject.rows[i]['menuUrl'] != '' && analyMsg.returnObject.rows[i]['menuUrl'] != null){
                        s = s + '<li><a href="javascript:openCommonMenu(' + analyMsg.returnObject.rows[i]['menuCode'] + ')" class="' + analyMsg.returnObject.rows[i]['moduleIcon'] + '"><span>' +  analyMsg.returnObject.rows[i]['menuDescription'] + '</span></a></li>';
                    }
                }
            }
        },
        error : function(data,textstatus){
            $.alert("default", "error", data.responseText)
        }
    });
    s = s + s_add;
    s = s + '</ol>';
    document.getElementById("div_cygn").innerHTML = s;
    hoverDhl("div_cygn");
}

function hoverDhl(id){
    $("#"+id).css("overflow","hidden");
    $("#"+id).hover(function(){
        $("#"+id).css("overflow","");
        $("#"+id).css("overflow-x","hidden");
    },function(){
        $("#"+id).css("overflow","hidden");
    });
}
